package com.hqd.ch03.v50.boot.autoconfigure.web.servlet;

import com.hqd.ch03.v50.web.servlet.DispatcherServlet;

import java.util.Collection;

public class DispatcherServletRegistrationBean extends ServletRegistrationBean<DispatcherServlet>
        implements DispatcherServletPath {

    private final String path;

    /**
     * Create a new {@link DispatcherServletRegistrationBean} instance for the given
     * servlet and path.
     *
     * @param servlet the dispatcher servlet
     * @param path    the dispatcher servlet path
     */
    public DispatcherServletRegistrationBean(DispatcherServlet servlet, String path) {
        super(servlet);
        this.path = path;
        super.addUrlMappings(getServletUrlMapping());
    }

    @Override
    public String getPath() {
        return this.path;
    }

    @Override
    public void setUrlMappings(Collection<String> urlMappings) {
        throw new UnsupportedOperationException("URL Mapping cannot be changed on a DispatcherServlet registration");
    }

    @Override
    public void addUrlMappings(String... urlMappings) {
        throw new UnsupportedOperationException("URL Mapping cannot be changed on a DispatcherServlet registration");
    }

}
